package org.sixtynine.stock.controller.front;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.sixtynine.stock.Constants.ChartType;
import org.sixtynine.stock.criteria.StockSearchCriteria;
import org.sixtynine.stock.model.ColData;
import org.sixtynine.stock.model.ColModel;
import org.sixtynine.stock.model.GridData;
import org.sixtynine.stock.service.StockManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

/**
 * @author Thilanka
 * 
 */
@Controller
public class TechnicalController extends AbstractGridController {

	@Autowired
	private StockManagerService service;

	@RequestMapping(value = "/technical/main")
	public ModelAndView showResults() {
		ModelAndView modelAndView = new ModelAndView("/technical/main");
		modelAndView.addObject("criteria", new StockSearchCriteria());
		showBannar(modelAndView);
		return modelAndView;
	}

	@RequestMapping(value = "/technical/list", method = RequestMethod.POST)
	@ResponseBody
	public GridData getData(
			@RequestParam(value = "page", required = false, defaultValue = "1") int page,
			@RequestParam(value = "rows", required = false) Integer rows,
			@RequestParam(value = "sidx", required = false) String sidx,
			@RequestParam(value = "sord", required = false) String sord,
			@RequestParam(value = "search", required = false) String search,
			@ModelAttribute StockSearchCriteria criteria,
			HttpServletRequest request) {

		criteria.setChartType(ChartType.GENERAL);
		return getGridData(criteria, page, rows, sidx, sord, search, request);
	}

	@RequestMapping(value = "/technical/colData", method = RequestMethod.GET)
	@ResponseBody
	public ColData getColumnData() {
		return getColData();
	}

	@Override
	public ColData getColData() {
		ColData colData = new ColData();

		List<ColModel> colModels = new ArrayList<ColModel>();

		colModels.add(new ColModel("ticker"));
		colModels.add(new ColModel("thertyMonthBeta")); //, "number", "right"
		colModels.add(new ColModel("sixtyMonthBeta"));
		colModels.add(new ColModel("averageTrueRange", "number", "right"));
		colModels.add(new ColModel("sma10", "number", "right"));
		colModels.add(new ColModel("sma20", "number", "right"));
		colModels.add(new ColModel("sma50", "number", "right"));
		colModels.add(new ColModel("sma100", "number", "right"));
		colModels.add(new ColModel("sma200", "number", "right"));
		colModels.add(new ColModel("twelMonthHigh", "number", "right"));
		colModels.add(new ColModel("twelMonthLow", "number", "right"));
		colModels.add(new ColModel("rsi", "number", "right"));
		colModels.add(new ColModel("changeOpenToNow", "number", "right"));
		colModels.add(new ColModel("gap", "number", "right"));
		colModels.add(new ColModel("currentSharePrice", "number", "right"));
		colModels.add(new ColModel("change", "number", "right"));
		colModels.add(new ColModel("volume", "integer", "right"));
		colData.setColModel(colModels);

		List<String> colNames = new ArrayList<String>();

		colNames.add("Ticker");
		colNames.add("Beta (36 M)");
		colNames.add("Beta (60 M)");
		colNames.add("ATR");
		colNames.add("SMA10");
		colNames.add("SMA20");
		colNames.add("SMA50");
		colNames.add("SMA100");
		colNames.add("SMA200");
		colNames.add("12M H");
		colNames.add("12M L");
		colNames.add("RSI");
		colNames.add("Change from open");
		colNames.add("GAP");
		colNames.add("Share Price(LKR)");
		colNames.add("Change %");
		colNames.add("Volume");
		colData.setColNames(colNames);
		return colData;
	}

}
